"use strict";
cc._RF.push(module, '22058iGHodEM5Gd9WMuiNFT', 'ContentScrollView');
// script/postalllistpage/ContentScrollView.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var GlobalData_1 = require("../GlobalData");
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var HttpUtils_1 = require("../../libs/lightMVC/util/HttpUtils");
var itemmove_1 = require("../itemmove");
var Socket_1 = require("../Socket");
var ContentScrollView = /** @class */ (function (_super) {
    __extends(ContentScrollView, _super);
    function ContentScrollView() {
        var _this_1 = _super !== null && _super.apply(this, arguments) || this;
        _this_1.scroll_view = null;
        _this_1.content = null;
        _this_1.anim_prefab = null;
        // LIFE-CYCLE CALLBACKS:
        // onLoad () {}
        //示例化socket
        _this_1.socket = null;
        return _this_1;
        // update (dt) {}
    }
    ContentScrollView.prototype.start = function () {
        var _this_1 = this;
        var resultValue = this.randResult();
        // console.log(resultValue);
        var _this = this;
        setTimeout(function () {
            _this.socket.sendMessage();
        }, 6000);
        var page = 1;
        this.add_item_content(page);
        var interval = setInterval(function () {
            if (page >= 25) {
                clearInterval(interval);
            }
            else {
                page++;
            }
            var r = _this_1.add_item_content(page);
        }, 3000);
    };
    //添加数据到scrollView
    ContentScrollView.prototype.add_item_content = function (page) {
        var _this_1 = this;
        var t_url = 'http://platform.qdmedia.cc/activity/space7_item';
        HttpUtils_1.default.Post(t_url, { page: page }, function (error, result) {
            if (result && !error) {
                var r = JSON.parse(result);
                // console.log(r)
                GlobalData_1.default.gameDatas = r;
                var data = GlobalData_1.default.gameDatas;
                var length = GlobalData_1.default.gameDatas.length;
                //添加数据
                for (var i = 0; i < length; i++) {
                    var item = cc.instantiate(_this_1.anim_prefab);
                    _this_1.content.addChild(item);
                    //y高度范围 -200~-800, x范围 1700~1900
                    var y = Math.random() * 600 + 150, x = Math.random() * 200 + 1700;
                    // item.y = -y;
                    if (page === 1) {
                        item.x = 800;
                    }
                    else if (page === 2) {
                        item.x = 1100;
                    }
                    else if (page === 3) {
                        item.x = 1550;
                    }
                    else {
                        item.x = 2300;
                    }
                    switch (i) {
                        case 1:
                            item.y = -(Math.random() * 100 + 150);
                            break;
                        case 2:
                            item.y = -(Math.random() * 100 + 300);
                            break;
                        case 3:
                            item.y = -(Math.random() * 100 + 450);
                            break;
                        case 4:
                            item.y = -(Math.random() * 100 + 600);
                            break;
                        default:
                            item.y = -(Math.random() * 600 + 150);
                            break;
                    }
                    // console.log(i,page,item.x,item.y);
                    item.getComponent(itemmove_1.default).init();
                    // data[i].id + '.' +  序号
                    item.getComponent(cc.Label).string = data[i].title;
                    //添加属性
                    var attr = { id: data[i].id, title: data[i].title };
                    item.attr(attr);
                }
            }
            else {
                return 'error';
            }
        });
    };
    /**
     * 获取结果页数据
     */
    ContentScrollView.prototype.randResult = function () {
        var list = [
            { 'key': 1, 'value': '春暖花开，有份姻缘在莫奈花园等你赴约', 'title': '脱单' },
            { 'key': 2, 'value': '努力是会上瘾的，成功的甜头就藏在七大洲里属于你的一隅', 'title': '脱单' },
            { 'key': 3, 'value': '挨过三冬四夏，登顶后看看莫奈花园的无限风光', 'title': '升职' },
            { 'key': 4, 'value': '理想生活化作清风拨动透气7音符，传出怡然的乐章向你袭来', 'title': '安康' },
            { 'key': 5, 'value': '坚持努力后的等价收获在约你览尽七大洲山河浪漫', 'title': '加薪' },
            { 'key': 6, 'value': '愿你言出意随，伴着美妙的7音符奔赴天然之约', 'title': '如意' },
            { 'key': 7, 'value': '世界上最好的保鲜是不断进步，继而成为七大洲中不可或缺的风景线', 'title': '暴瘦' },
        ];
        var k = Math.floor(Math.random() * 6 + 1);
        return list[k];
    };
    __decorate([
        property(cc.ScrollView)
    ], ContentScrollView.prototype, "scroll_view", void 0);
    __decorate([
        property(cc.Node)
    ], ContentScrollView.prototype, "content", void 0);
    __decorate([
        property(cc.Prefab)
    ], ContentScrollView.prototype, "anim_prefab", void 0);
    __decorate([
        property(Socket_1.default)
    ], ContentScrollView.prototype, "socket", void 0);
    ContentScrollView = __decorate([
        ccclass
    ], ContentScrollView);
    return ContentScrollView;
}(cc.Component));
exports.default = ContentScrollView;

cc._RF.pop();